﻿using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using Microsoft.Commerce.Proxy.AccountService;

namespace TestWebApplication.CommerceAccount.APIs
{
    public class CommerceAccountUpdateAccountApi : CommerceAccountApi
    {
        private UpdateAccountInput input;
        private UpdateAccountOutput output;

        private AccountInfo accountInfo;
        private CallerInfo callerInfo;

        public CommerceAccountUpdateAccountApi(BasicHttpBinding binding, EndpointAddress address, X509Certificate2 clientCert, AccountInfo accountInfo, CallerInfo callerInfo)
            : base(binding, address, clientCert)
        {
            this.accountInfo = accountInfo;
            this.callerInfo = callerInfo;
        }

        public CommerceUserAccount Account { get; private set; }

        protected override AbstractResponse ExecuteInternal(AccountServiceChannel channel)
        {

            this.output = channel.UpdateAccount(this.input);

            return output;
        }

        public override void PrepareRequestData()
        {
            this.input = new UpdateAccountInput()
            {
                APIContext = new APIContext()
                {
                    TrackingGuid = this.trackingGuid,
                },

                CallerInfo = this.callerInfo,
                AccountInputInfo = this.accountInfo
            };
        }

        public override void PrepareResponseData()
        {
            this.Account = new CommerceUserAccount()
            {
                AccountInfo = this.output.AccountOutputInfo
            };

            return;
        }
    }
}
